<?php
class Controller_Admin_Login extends Controller {
	function __construct(Request $request, Response $response) {
        parent::__construct($request, $response);				
	}

	/**
	 * display form cho user login
	 */
	public function action_index()
	{

		if (Request::current()->method() == 'POST')
		{
			$inputs = Arr::extract($_POST,array('email', 'password'));
			if (Api::load('user')->login($inputs['email'], $inputs['password'], 'admin'))
			{
				Request::current()->redirect('admin/dashboard');	
			}
			else
			{
				Flashmessage::getInstance()->add('Xác thực thất bại');
			}

			
		}

		$styles = array(
            URL::site('assets/admin/css/reset.css'),
            URL::site('assets/admin/css/style.css'),
            URL::site('assets/admin/css/invalid.css'),
        );
        $scripts = array(
            URL::site('assets/admin/js/jquery-1.6.min.js?' . time()),
            URL::site('assets/admin/js/simpla.jquery.configuration.js?' . time()),
            URL::site('assets/admin/js/facebox.js?' . time()),            
            URL::site('assets/admin/js/jquery.date.js?' . time()),
            URL::site('assets/admin/js/sidebar.js?' . time()),
        );



		$this->response->body(View::factory('admin/user/page_admin_login', array(
			'styles' => $styles,
			'scripts' => $scripts,
		)));
	}

}